package com.lyf.core.dao; 

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import com.lyf.core.log.aspect.InfoLog;
 

@Repository
public interface LogDao {

	@Insert("insert into public.info_log(uid,user_name,model,name,content,optype,result,exception,crtime)"
			+ " values (#{log.uid},#{log.user_name},#{log.model},#{log.name},#{log.content},#{log.optype},#{log.result},#{log.exception},#{log.crtime})")
	public void insert(@Param("log") InfoLog log);
	
	
	 /**
     * 
    * 
    * @param 
    * @return 
    * @exception
     */
 /*   @Select( 
		"select crtime,user_id,model,title,content,opType,result,exception,schema,project_name"+ 
		" from public.info_log "+
		" where crtime between #{start} and #{end} "
		+ " order by t1.login_time desc limit #{rows} offset (#{page}-1)*#{rows} " 
	 )*/
    @Select({"<script>",  
    	 
		"select * ", 
				" from public.info_log ",
				" where 1 = 1   ",
				"<when test='start != null  '>",
				 "<![CDATA["  ,
				" and crtime >= #{start}" ,
				"]]>"  ,
				"</when>"  ,
				"<when test='end != null  '>",
				 "<![CDATA["  ,
				" and crtime <= #{end}" ,
				"]]>"  ,
				"</when>"  ,
				"<when test='uid != null  '>",
					" and uid = #{uid}" ,
				"</when>"  ,
				" order by crtime desc limit #{rows} offset (#{page}-1)*#{rows} " ,
			
			"</script>"
	})
    public List<InfoLog> selectDetailsModel(@Param("start")Date start ,@Param("end") Date end , @Param("uid")Integer uid ,@Param("page") int page ,@Param("rows") int rows);
    
    @Select({"<script>",  
     
		"select *  ", 
				" from public.info_log ",
				" where 1 = 1 ",
				"<when test='start != null  '>",
				 "<![CDATA["  ,
				" and crtime >= #{start}" ,
				"]]>"  ,
				"</when>"  ,
				"<when test='end != null  '>",
				 "<![CDATA["  ,
				" and crtime <= #{end}" ,
				"]]>"  ,
				"</when>"  ,
				"<when test='uid != null  '>",
					" and uid = #{uid}" ,
				"</when>"  ,
				" order by crtime desc limit 65534" ,
			 
	 "</script>"
	})
    public List<InfoLog> selectDetails(@Param("start")Date start ,@Param("end") Date end , @Param("uid")Integer uid );
    
    
   /* @Select("select count(1) from public.user_login_info where login_time between #{start} and #{end} and username = #{user} ")
   */ 
    @Select({"<script>",  
    	 
    	"select count(1)", 
		" from public.info_log ", 
		" where 1 = 1 ",
		"<when test='start != null  '>",
		 "<![CDATA["  ,
		" and crtime >= #{start}" ,
		"]]>"  ,
		"</when>"  ,
		"<when test='end != null  '>",
		 "<![CDATA["  ,
		" and crtime <= #{end}" ,
		"]]>"  ,
		"</when>"  ,
		"<when test='uid != null  '>",
			" and uid = #{uid}" ,
		"</when>"  ,
		 
	 "</script>"
	})
    public int  selectDetailsCnt(@Param("start")Date start ,@Param("end") Date end , @Param("uid")Integer uid);
    
	
}

